package com.dragon.repository.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dragon.repository.entity.ArrangePersonnel;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 考勤配置人员关联 Mapper 接口
 * </p>
 *
 * @author sy
 * @since 2023-07-31
 */
@Mapper
public interface ArrangePersonnelMapper extends BaseMapper<ArrangePersonnel> {

    /**
     * 获取部门名称
     * @param departmentId
     * @return
     */
    @Select("select GROUP_CONCAT(b.`name`) from dragon_arrange_personnel a " +
            "LEFT join dragon_department b on FIND_IN_SET(b.id,#{departmentId}) " +
            "WHERE a.id = #{personnelId}   ")
    List<String> getDepartmentNames(String departmentId, Integer personnelId);

    /**
     * 获取用户名称
     * @param adminId
     * @param personnelId
     * @return
     */
    @Select("select GROUP_CONCAT(d.username) as adminName from dragon_arrange_personnel a " +
            "LEFT JOIN dragon_admin d  on a.admin_id = d.id " +
            "WHERE a.arrange_id = #{personnelId} ")
    String getAdminNames(Integer personnelId);
}
